﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Bussiness
{
    /// <summary>
    /// 报警点
    /// </summary>
    public class AlarmPoint
    {
        /// <summary>
        /// 测点号
        /// </summary>
        public string PIPoint { get; set; }
        /// <summary>
        /// 测点名称
        /// </summary>
        public string PIName { get; set; }
        /// <summary>
        /// 上限
        /// </summary>
        public double HighLimit { get; set; }
        /// <summary>
        /// 下限
        /// </summary>
        public double LowerLimit { get; set; }
        /// <summary>
        /// 跳闸值
        /// </summary>
        public string Limit { get; set; }
        /// <summary>
        /// 上限描述
        /// </summary>
        public string HighDescription { get; set; }
        /// <summary>
        /// 下限描述
        /// </summary>
        public string LowDescription { get; set; }
        /// <summary>
        /// 指导类型
        /// </summary>
        public string Catalog { get; set; }
        /// <summary>
        /// 取所有描述
        /// </summary>
        /// <returns></returns>
        public DataTable GetAlarmDescription()
        {
            DataTable NEWDT = GenerateAlarmColumn();
            string sql = "SELECT 上限描述,下限描述 FROM ADMINISTRATOR.T_ALARM_INFO";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr[0].ToString() != "")
                        NEWDT.Rows.Add(dr[0].ToString());
                    if (dr[1].ToString() != "")
                        NEWDT.Rows.Add(dr[1].ToString());
                }
            }
            return NEWDT;
        }
        /// <summary>
        /// 生成报警列
        /// </summary>
        /// <returns></returns>
        public DataTable GenerateAlarmColumn()
        {
            DataTable dt = new DataTable();
            DataColumn col1 = new DataColumn("ALARM");
            dt.Columns.Add(col1);
            return dt;
        }
        /// <summary>
        /// 返回报警点描述集
        /// </summary>
        /// <returns></returns>
        public System.Data.DataTable GetAlarmPoint()
        {
            string sql = "SELECT * FROM ADMINISTRATOR.T_ALARM_INFO ";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回报警描述集
        /// </summary>
        /// <returns></returns>
        public System.Data.DataTable GetParaDescription()
        {
            string sql = "SELECT DISTINCT(上限描述) FROM ADMINISTRATOR.T_ALARM_INFO ";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 更新报警点
        /// </summary>
        /// <param name="id_key">编号</param>
        public void Update(int id_key)
        {
            string sql = "UPDATE ADMINISTRATOR.T_ALARM_INFO SET 测点名称='" + PIName + "' ,下限=" + LowerLimit + ",上限=" + HighLimit + ",上限描述='" + HighDescription + "',跳闸值=" + Limit + " WHERE ID_KEY=" + id_key;
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            link.Excute(sql);
        }
        /// <summary>
        /// 删除报警数据
        /// </summary>
        public void Delete(int id_key)
        {
            string sql = "DELETE FROM ADMINISTRATOR.T_ALARM_INFO WHERE ID_KEY=" + id_key;
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            link.Excute(sql);
        }
        /// <summary>
        /// 添加测点描述
        /// </summary>
        public void Add()
        {
            string sql = "";
            if (Limit == "")
                sql = "INSERT INTO ADMINISTRATOR.T_ALARM_INFO(测点名称,下限,上限,上限描述,测点号,下限描述,负荷测点,负荷限值,类别) VALUES('" + PIName + "'," + LowerLimit + "," + HighLimit + ",'" + HighDescription + "','" + PIPoint + "','" + LowDescription + "','CSPC:01CE30001',300,'"+Catalog+"')";
            else
                sql = "INSERT INTO ADMINISTRATOR.T_ALARM_INFO(测点名称,下限,上限,上限描述,测点号,跳闸值,下限描述,负荷测点,负荷限值,类别) VALUES('" + PIName + "'," + LowerLimit + "," + HighLimit + ",'" + HighDescription + "','" + PIPoint + "'," + Limit + ",'" + LowDescription + "','CSPC:01CE30001',300,'" + Catalog + "')";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            link.Excute(sql);
        }
    }

    public class Alarm
    {
        public string AlarmDESC { get; set; }
    }
}
